<template>
    <h1>注册页面</h1>

    <table>
        <tr>
            <td>用户名:</td>
            <td>
                <input type="text" v-model="Info.U_Name" >
            </td>
        </tr>

        <tr>
            <td>密码：</td>
            <td>
                <input type="password" v-model="Info.U_Pwd" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="注册" @click="UserAdd">
            </td>
        </tr>

    </table>


</template>

<script setup lang="ts">

import { ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter();

const Info = ref({
    U_Name:'',
    U_Pwd:'',
})

const UserAdd =() =>{
    axios({
        method:'post',
        url:'http://localhost:64202/api/User/UserAdd',
        data:{
            U_Name:Info.value.U_Name,
            U_Pwd:Info.value.U_Pwd,
        }
    })
    .then(function(res){
        if(res.data>0){
            alert('注册成功')
            router.push('/Login')
        }
        else if(res.data==-1){
            alert('用户名已存在');
            return;
        }
        else {
            alert('注册失败');
            return;
        }
    })
    .catch(function(err){
        console.log(err)
    })
}
    


</script>
